package com.atguigu.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;


@ToString
public class OrderConfirmVo {

    //收获地址
    @Setter@Getter
    List<MemberAddressVo> address;

    //购物车订单
    @Setter@Getter
    List<OrderItemVo> items;

    //优惠券信息
    @Setter@Getter
    Integer integration;

    //订单总额

    BigDecimal total;

    @Setter@Getter
    Map<Long,Boolean> stocks;


    //订单总额
    public BigDecimal getTotal(){
        BigDecimal sum = new BigDecimal("0");
        if(items!=null){
            for (OrderItemVo item : items) {
                //BigDecimal只能和BigDecimal做运算，运算之前要包装为BigDecimal类，
                // 类里面的要是字符，包装的时候
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    //应付价格
    BigDecimal payPrice;

    //目前没有优惠系统，payPrice就是total
    public BigDecimal getPayPrice(){
        return getTotal();
    }

    //订单放重令牌
    @Getter@Setter
    String orderToken;

    public Integer getCount(){
        Integer i = 0;
        if(items!=null){
            for (OrderItemVo item : items) {
               i+= item.getCount();
            }
        }
        return i;
    }

}
